//添加购物车api

import type { CartItem, CartParams, CartResult } from '@/types/car'
import { http } from '@/utils/http'

/**
 * 加入购物车
 * @param data
 * @returns
 */
export const addCartAPI = (data: CartParams) => {
  return http<CartResult>({
    method: 'POST',
    url: '/member/cart',
    data,
  })
}

/**
 * 获取购物车列表
 * @returns
 */
export const getCartListAPI = () => {
  return http<CartItem[]>({
    method: 'GET',
    url: '/member/cart',
  })
}

/**
 * 清空购物车
 * @param ids 商品id集合
 * @returns
 */
export const removeCartAPI = (ids: string[]) => {
  return http<number>({
    method: 'DELETE',
    url: '/member/cart',
    data: { ids },
  })
}

/**
 * 修改购物车单品
 * @param skuId 路径参数
 * @param data
 * @returns
 */
export const updateCartAPI = (skuId: string, data: { selected?: boolean; count?: number }) => {
  return http<CartResult>({
    method: 'PUT',
    url: `/member/cart/${skuId}`,
    data,
  })
}

/**
 * 购物车全选/取消全选
 * @param selected 选中状态
 * @returns
 */
export const selectCartAPI = (selected: boolean) => {
  return http<number>({
    method: 'PUT',
    url: '/member/cart/selected',
    data: { selected },
  })
}
